package com.yanqu.road.server.cmd.wineshop;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.wineshop.WineShopProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.wineshop.WineShopModule;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_WINESHOP_BUILDING_UPGRADE_ONE_KEY, desc = "酒肆建筑升级(同步升级)")
public class WineShopBuildingUpgradeOneKeyCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        WineShopProto.WineShopBuildingUpgradeOneKeyReqMsg reqMsg = WineShopProto.WineShopBuildingUpgradeOneKeyReqMsg.parseFrom(packet.getBytes());
        ret = player.getModule(WineShopModule.class).buildingUpgradeOneKey(reqMsg.getAreaId());
    }

    @Override
    public void sendData(GamePlayer player) {
        if(ret != 0) {
            WineShopProto.WineShopBuildingUpgradeOneKeyRespMsg.Builder respMsg = WineShopProto.WineShopBuildingUpgradeOneKeyRespMsg.newBuilder();
            respMsg.setRet(ret);
            player.sendPacket(ClientProtocol.U_WINESHOP_BUILDING_UPGRADE_ONE_KEY, respMsg);
        }
    }
}
